<import file="block/common.html" name="url" :tpl_cfg="['urlName'=>$title,'backList'=>'返回列表']"/>
<div class="layui-fluid">
	<div class="layui-form">
		<div class="layui-form-item">
			<label class="layui-form-label required">选择栏目</label>
			<div class="layui-input-inline">
				<select name="cid" lay-verify="">
					<php foreach="$catelist as $key=>$vo">
					  <option value="<{$vo['id']}>" <?php if(!empty($info)){echo $info['cid'] == $vo['id']?'selected=""':'';}?>><{$vo['name']}></option>
					</php> 
					</select> 
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">标题</label>
			<div class="layui-input-block">
				<input type="text" name="title" lay-verify="required" lay-reqtext="标题不能为空" placeholder="请输入标题"
					value="<{$info['title']??''}>" class="layui-input">
			</div>
		</div>
		
		<div class="layui-form-item">
			<label class="layui-form-label required">审核人</label>
			<div class="layui-input-inline">
				<input type="text" name="examine" lay-verify="required" lay-reqtext="审核人不能为空" placeholder="请输入审核人"
					value="<{$info['examine']??''}>" class="layui-input">
			</div>
		</div>
		<?php if(SysRolCk("video_attribute")){ ?>
		<div class="layui-form-item">
			<label class="layui-form-label required">内容属性</label>
			<div class="layui-input-block">
				<input type="checkbox" name="att_a" value="1" title="视频头条"
					<?php if(!empty($info)){echo $info['att_a'] == 1?'checked=""':'';}?>>
				<input type="checkbox" name="att_b" value="1" title="视频小头条"
					<?php if(!empty($info)){echo $info['att_b'] == 1?'checked=""':'';}?>>
				<span id="lunhuantu">
					<input type="checkbox" name="att_c" value="1" title="视频轮换"
					<?php if(!empty($info)){echo $info['att_c'] == 1?'checked=""':'';}?>>
				</span>
			</div>
		</div>
		<?php } ?>
			<div class="layui-form-item">
				<label class="layui-form-label required">视频地址</label>
				<div class="layui-input-block" style="width: 500px;">
					<input type="text" id="videourl" name="videourl" value="<{$info['videourl']??''}>" class="layui-input">
					<?php if(SysRolCk("upload_upload")){ ?>
						<div style="width: 500px;">
							<div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="uploadProgress">
							  <div class="layui-progress-bar" lay-percent=""></div>
							</div>
						  </div>
					<div>	  
					<button type="button" class="layui-btn" id="videoupload">
						<i class="layui-icon">&#xe67c;</i>上传视频
					</button>
					</div>
					<tip>不超过<{$upload['videouploadsize']}>KB！ 支持格式：<{$upload['videouploadext']}></tip>	
<div class="layui-form-mid layui-word-aux">不建议上传大文件，如需要请检查PHP.INI 的 post_max_size 等配置。</div>
					<?php } ?>
				</div>
				
			</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">视频轮换图</label>
			<div class="layui-input-block" style="width: 500px;">
				<?php if(SysRolCk("upload_upload")){ ?>
				<input type="text" id="imageval" name="img" value="<{$info['img']??''}>" class="layui-input">
				<button type="button" class="layui-btn" id="thumimg">
				  <i class="layui-icon">&#xe67c;</i>上传缩略图
				</button>
				<?php } ?>
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">视频描述</label>
			<div class="layui-input-block">
				<textarea id="contentEdit" name="content"><{$info['content']??''}></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">状态</label>
			<div class="layui-input-inline">
				<?php if(SysRolCk("video_status")){ ?>
					<input type="radio" name="status" value="1" title="发布" <?php if(!empty($info)){if($info['status'] == 1){echo 'checked';}}?>>
				<?php } ?>
					<input type="radio" name="status" value="0" title="草稿" <?php if(!empty($info)){if($info['status'] == 0){echo 'checked';}}?>>
			</div>
				<?php if(!SysRolCk("video_status")){ ?>
					<div class="layui-form-mid layui-word-aux">你没有直接发布内容权限，如果你修改了本条内容，所有该本条内容的头条、小头条或其它不属于您权限的设置将失效！</div>
				<?php } ?>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="hidden" name="id" value="<{$info['id']??''}>">
				<button class="layui-btn" lay-submit lay-filter="saveBtn"><i class="layui-icon">&#x1005;</i><?php echo lang('save');?></button>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript" src="<?php echo U_RES;?>/lib/tinymce/tinymce.min.js?v=6"></script>
<script>
	layui.define(function () {
		var form = layui.form,
			layer = layui.layer,
			table = layui.table,
			upload = layui.upload,
			element = layui.element,
			$ = layui.$;

		form.render();

		//监听提交 +=>
		form.on('submit(saveBtn)', function (data) {
			$.post('<{CAUrl("video",ROUTE["act"])}>',
				{
					cid: data.field.cid,
					title: data.field.title,
					videourl: data.field.videourl,
					att_a: data.field.att_a,
					att_b: data.field.att_b,
					att_c: data.field.att_c,
					examine: data.field.examine,
					img: data.field.img,
					content: tinyMCE.activeEditor.getContent(),
					status: data.field.status,
					id: data.field.id
				},
				function (res) {
					if (res.status == 1) {
						layer.msg(res.info, { icon: 1, time: 1000 }, function () {
							loadMain('<{CAUrl("video","index")}>&cid=' + res.cid);
						});
					} else {
						layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
					}
				});
			return false;
		});

		var uploadInst = upload.render({
			elem: '#thumimg' //绑定元素
			, url: '<{CAUrl("upload","upload")}>&up=img' //图片上传接口
			, size: "<{$upload['imguploadsize']}>"
			, accept: 'images'
			, acceptMime: 'image/*'
			//,acceptMime: 'image/jpg, image/png'
			, exts: "<{$upload['imguploadext']}>".replace(/./g, '')
			, done: function (res) {
				if (res.status == 1) {
					$.post("<{CAUrl('upload','upload')}>&up=img&del", { url: "<{$info['img']??''}>"});//删除旧文件
					$('#imageval').val(res.result[0].src);					
					layer.msg(res.info);
				} else {
					layer.msg(res.info);
				}
			}
			, error: function () {
				//请求异常回调
			}
		});

		var uploadVideo = upload.render({
			elem: '#videoupload' //绑定元素
			, url: '<{CAUrl("upload","upload")}>&up=video' //附件上传接口
			, size: "<{$upload['videouploadsize']}>"
			, accept: 'file'
			, acceptMime: 'file/*'
			,acceptMime: 'video/mp4, video/avi'
			//, exts: 'zip|rar|7z|doc|docx|xlsx|xls|'
			, exts: "<{$upload['videouploadext']}>".replace(/./g, '')
			,before: function(obj){
			element.progress('uploadProgress', '0%'); //进度条复位
			}
			, done: function (res) {
				if (res.status == 1) {
					$.post("<{CAUrl('upload','upload')}>&up=video&del", { url: "<{$info['videourl']??''}>"});//删除旧文件
					$('#videourl').val(res.result[0].src);
					//res.result[0].src + res.result[0].suffix + res.result[0].size
					layer.msg(res.info);
				} else {
					layer.msg(res.info);
				}
			}
			, error: function () {
				//请求异常回调
			}//进度条
			,progress: function(n, elem, e){
			element.progress('uploadProgress', n + '%'); //可配合 layui 进度条元素使用
			if(n == 100){
				layer.msg('上传完毕', {icon: 1});
			}
			}
		});

	});

	//如果没有缩略图，就不能选择 轮换图
	var imageval = $('#imageval').val();
	if (imageval.length < 1) {
		$('#lunhuantu').hide();
	} else {
		$('#lunhuantu').show();
	}
	$('#imageval').bind('input propertychange', function () {
		if ($(this).val().length) {
			$('#lunhuantu').show();
		} else {
			$('#lunhuantu').hide();
		}

	});

	tinymce.init({
			selector: '#contentEdit',
			language: 'zh_CN',
			relative_urls: false,
			remove_script_host: true,
			plugins: 'print preview searchreplace autolink directionality visualblocks visualchars image link media template code codesample table charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists wordcount imagetools textpattern help emoticons autoresize lineheight axupimgs',
			toolbar: 'code | undo redo restoredraft | cut copy paste | forecolor bold italic underline link | alignleft aligncenter alignright alignjustify outdent indent | fontselect fontsizeselect | table <?php if(SysRolCk("upload_upload")){ ?>image<?php } ?> charmap emoticons insertdatetime preview | lineheight <?php if(SysRolCk("upload_upload")){ ?>axupimgs<?php } ?>',
			//引用lineheight插件，会导致  Uncaught SyntaxError: Unexpected token '<'  错误，暂时未解决！！
			autosave_interval: "20s",//自动存稿时间
			font_formats: '微软雅黑=Microsoft YaHei,sans-serif;仿宋_GB2312=仿宋_GB2312,Microsoft YaHei,sans-serif;宋体=宋体;仿宋=仿宋;黑体=黑体',
			height: 650, //编辑器高度
			min_height: 400,
			lineheight_formats : '1 1.5 2 2.5 3',
			draggable_modal: true,
			images_upload_base_path: '/',
			images_upload_handler: function (blobInfo, succFun, failFun) {
			var xhr, formData;
			var file = blobInfo.blob();//转化为易于理解的file对象
			xhr = new XMLHttpRequest();
			xhr.withCredentials = false;
			xhr.open('POST', '<{CAUrl("upload","upload")}>&up=img&tinymce');
			xhr.onload = function() {
				var json;
				if (xhr.status != 200) {
					failFun('HTTP Error: ' + xhr.status);
					return;
				}
				json = JSON.parse(xhr.responseText);
				if (!json || typeof json.location != 'string') {
					failFun('Invalid JSON: ' + xhr.responseText);
					return;
				}
				succFun(json.location);
			};
			formData = new FormData();
			formData.append('file', file, file.name );
			xhr.send(formData);
		}
		});
</script>